import { Navigate, useRoutes } from "react-router-dom";
import type { ReactNode } from "react";
import type { RouteObject } from "react-router-dom";
import React from "react";
import { HOME_URL } from "../pageConfig";
import system from "./modules/system";
import userInfo from "./modules/userInfo";
type CustomRouteObject = Omit<RouteObject, "children"> & {
  children?: CustomRouteObject[];
  label?: string;
  title?: string;
  icon?: ReactNode;
  meta?: object;
  isLink?: string;
};

const routerArray = [...system, ...userInfo];

export const rootRouter: CustomRouteObject[] = [
  {
    path: "/",
    element: <Navigate to={HOME_URL} />,
  },
  ...routerArray,
  {
    path: "*",
    element: <Navigate to="/404" />,
  },
];

const Router = () => {
  return useRoutes(rootRouter as RouteObject[]);
};
export default Router;
